#！/bin/bash

echo "开始配置自动格式化..."
spaceDir=~/.spacecommander
repoAdd=https://git.jd.com/jingxi_ios/spacecommander.git
current_repo_path=$(git rev-parse --show-toplevel)
formatFile=$current_repo_path/.clang-format
echo $formatFile

if [ ! -d "$spaceDir" ];then
    rm -rf "$spaceDir"
    git clone "$repoAdd" "$spaceDir"
fi

if [ -e "$formatFile" ];then
    echo "Already has clang-format file"
    if [ "$0" == "bash" ];then
        echo "use git pull to update spacecommander"
        cd $spaceDir
        git pull
    fi
else
    echo "Has no clang-format file"
    cd $current_repo_path
    bash "$spaceDir"/setup-repo.sh
    touch .formatting-directory-ignore
    echo "Example/Pods" > .formatting-directory-ignore
    ruby $spaceDir/addRunScript.rb "$current_repo_path"
    cat .gitignore | grep '.formatting-directory-ignore' > /dev/null
    if [ $? != 0 ] ; then
        echo ".formatting-directory-ignore" >> .gitignore
    fi
fi
echo "配置完成"